const express = require('express');
const router = express.Router();
const familyController = require('../controllers/familyController');
const authMiddleware = require('../middleware/authMiddleware');

// 所有家庭相关路由都需要身份验证
router.use(authMiddleware.authenticateToken);

// 获取当前用户的家庭信息
router.get('/', familyController.getUserFamily);

// 创建新家庭
router.post('/', familyController.createFamily);

// 更新家庭信息
router.put('/:familyId', familyController.updateFamily);

// 添加家庭成员
router.post('/:familyId/members', familyController.addFamilyMember);

// 更新家庭成员角色
router.put('/:familyId/members/:memberId/role', familyController.updateMemberRole);

// 移除家庭成员
router.delete('/:familyId/members/:memberId', familyController.removeFamilyMember);

// 更新设备共享状态
router.put('/:familyId/devices/:deviceId/sharing', familyController.updateDeviceSharing);

// 获取用户可以访问的共享设备
router.get('/shared-devices', familyController.getUserSharedDevices);

module.exports = router; 